define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http) {
		/**
		 * 一键切换数据获取方式
		 * @param {Object} result
		 */
		function get_data_list(result) {
			if(false) {
				result = '{"success": true,"msg": "","result":' +
						' {"doing": [{"act_id": "act_id_001","name": "新年促销","start_time": "2017/01/01 09:00:00","end_time": "2017/01/31 09:00:00","image": {"id": "001","image": "./img/upload/pro-img01.jpg"}},{"act_id": "act_id_002","name": "新年促销","start_time": "2017/01/01 09:00:00","end_time": "2017/01/31 09:00:00","image": {"id": "001","image": "./img/upload/pro-img01.jpg"}}],' +
						'"pending": [{"act_id": "act_id_003","name": "新客户促销","start_time": "2017/01/01 09:00:00","end_time": "2017/01/31 09:00:00","image": {"id": "001","image": "./img/upload/pro-img01.jpg"}},{"act_id": "act_id_004","name": "新客户促销","start_time": "2017/01/01 09:00:00","end_time": "2017/01/31 09:00:00","image": {"id": "001","image": "./img/upload/pro-img01.jpg"}}],' +
						'"ended": [{"act_id": "act_id_005","name": "圣诞促销","start_time": "2017/01/01 09:00:00","end_time": "2017/01/31 09:00:00","image": {"id": "001","image": "./img/upload/pro-img01.jpg"}},{"act_id": "act_id_006","name": "圣诞促销","start_time": "2017/01/01 09:00:00","end_time": "2017/01/31 09:00:00","image": {"id": "001","image": "./img/upload/pro-img01.jpg"}}]},' +
						'"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}
		function get_data_groupbuy_list(result){
			if(false){
				result = '{"success":true,"msg":"","result":{"act":[{"act_id":"act_id_001","act_name":"新年促销","store_id":"001","store_name":"上海五金店","start_time":"2017/01/01 09:00:00","end_time":"2017/01/31 09:00:00","introduction":"新年里的团购信息","goods_count":10,"member_count":100,"image":{"id":"001","image":"./img/upload/pro-img01.jpg"}},{"act_id":"act_id_002","act_name":"新年促销","store_id":"001","store_name":"上海五金店","start_time":"2017/01/01 09:00:00","end_time":"2017/01/31 09:00:00","introduction":"新年里的团购信息","goods_count":10,"member_count":100,"image":{"id":"001","image":"./img/upload/pro-img01.jpg"}}]},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			}else
			return result;
		}
		
		//返回信息
		return {
			groupbuy_list:function(nPage,act_type,callback,calldone){
				Http.post({
					method:'marketing.groupbuy.viewlist',
					pagelimit:10,
					nPage:nPage,
					act_type:act_type
				},function(result){
					if(callback)
					callback(get_data_groupbuy_list(result).result,get_data_groupbuy_list(result).process_time);
				},function(e){
					
				},function(){
					if(calldone)
					calldone();
				})
			},
			//轮播图
			getBannerList: function(callback) {
				Http.post({
					method: 'marketing.banner.getlist',
					act_type:1
				}, function(result) {
					if(callback) {
						callback(result);
					}
				}, function(e) {
					//请求异常
				}, function() {
					
				});
			}
			
			
		};
	}

	factory.$inject = ['Http'];
	return app.registerService("Groupbuy", factory);
});